package com.shiguiwu.springboot3.plugin;

import com.shiguiwu.springboot3.domain.Person;
import com.shiguiwu.springboot3.enums.Color;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import java.io.File;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;
import java.util.Properties;

/**
 * @description: 插件类
 * @author: stone
 * @date: Created by 2023/7/12 22:20
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springboot3.plugin
 */
@Mojo(name = "myPlugin")
public class MyMojo extends AbstractMojo {


    /**
     * 要显示的问候语。
     */
    @Parameter(property = "sayhi.greeting", defaultValue = "Hello World!" )
    private String greeting;

    @Parameter
    private boolean myBoolean;

    @Parameter
    private Integer myInteger;

    /**
     * 枚举
     */
    @Parameter
    private Color myColor;
    /**
     * My Array.
     */
    @Parameter
    private String[] myArray;
    /**
     * 文件类型
     */
    @Parameter
    private File myFile;


    /**
     * My List.
     */
    @Parameter
    private List myList;

    @Parameter
    private Map<String,Object> myMap;


    /**
     * My Properties.
     */
    @Parameter
    private Properties myProperties;

    /**
     * 人
     */
    @Parameter
    private Person person;
    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {
        this.getLog().info("hello my first maven plugin!");

        Field[] declaredFields = this.getClass().getDeclaredFields();

        List.of(declaredFields).forEach(f -> {
            if (f.canAccess(this)) {
                f.setAccessible(true);
            }

            try {
                this.getLog().info(f.getName() + ":" + f.get(this));
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }

        });
    }
}
